import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.gwc.mapper.CustomerMapper;
import org.gwc.pojo.Customer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

public class TsetCustomer {
    private SqlSession sqlSession;

    @BeforeEach // 每个测试方法执行之前都需执行的方法
    public void before() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        sqlSession = sqlSessionFactory.openSession(true); // 自动提交事务
    }

    @AfterEach // 每个测试方法执行之后都需执行的方法
    public void after(){
        sqlSession.close();
    }

    @Test
    public void testCustomerWithOrder(){
        CustomerMapper customerMapper = sqlSession.getMapper(CustomerMapper.class);
        Customer customer = customerMapper.selectCustomerWithOrderList(1);
        System.out.println("customer = " + customer);
    }
}
